﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Diagnostics;


namespace GameOnCopyBook.Time
{
    [Serializable]
    class BestTime
    {
        private int record;

        public int Record
        {
            get { return record; }
            set { record = value; }
        }
    
    }

    class ScoreManager
    {
        public void SaveBestTime(int bt)
        {
            FileStream stream = File.Open("BestTime.sav", FileMode.OpenOrCreate, FileAccess.Write);
            try
            {
                BinaryFormatter serializer = new BinaryFormatter();
                serializer.Serialize(stream, bt);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            finally
            {
                stream.Close();
            }

        }

        public int LoadBestTime()
        {
            int bt = 0;

            FileStream stream = File.Open("BestTime.sav", FileMode.OpenOrCreate, FileAccess.Read);

            try
            {
                BinaryFormatter serializer = new BinaryFormatter();
                bt = (int)serializer.Deserialize(stream);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            finally
            {
                stream.Close();
            }

            return bt;
        }
    }


}
